﻿using System.Web.Mvc;
using System.Web.Routing;
using Castle.Windsor.Installer;
using GdNet.Integrations.Castle.Web;

namespace GdNet.WebFramework.Gui
{
    public class MvcApplication : CastleHttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        protected override void OnApplicationStart()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            base.OnApplicationStart();
        }

        protected override void RegisterWindsorInstallers()
        {
            base.RegisterWindsorInstallers();
            AddWindsorInstaller(FromAssembly.This());
        }
    }
}